package se.thoka.twt.client.item;

import java.util.Collection;
import java.util.List;

import se.thoka.twt.client.event.ListItemClickedHandler;
import se.thoka.twt.client.event.ListItemMouseOutHandler;
import se.thoka.twt.client.event.ListItemMouseOverHandler;
import se.thoka.twt.client.utils.TWTListBase;
import se.thoka.twt.client.widgets.TWTList;

import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;

public class ListItemViewRenderer<T extends Item<T>> implements ItemViewRenderer<T>, TWTListBase<ItemRenderer<T>> {
	
	private final TWTList<ItemRenderer<T>> list;
	
	public ListItemViewRenderer() {
		this(new TWTList<ItemRenderer<T>>());
	}
	
	public ListItemViewRenderer(TWTList<ItemRenderer<T>> list) {
		if (list == null) {
			throw new NullPointerException("List widget must not be null.");
		}
		this.list = list;
	}

	@Override
	public void add(ItemRenderer<T> item) {
		list.add(item);
	}

	@Override
	public void addAll(Collection<ItemRenderer<T>> items) {
		list.addAll(items);
	}

	@Override
	public Widget asWidget() {
		return list;
	}

	@Override
	public void clear() {
		list.clear();
	}

	@Override
	public boolean remove(ItemRenderer<T> item) {
		return list.remove(item);
	}

	@Override
	public HandlerRegistration addListItemClickedHandler(ListItemClickedHandler<ItemRenderer<T>> handler) {
		return list.addListItemClickedHandler(handler);
	}

	@Override
	public HandlerRegistration addListItemMouseOverHandler(ListItemMouseOverHandler<ItemRenderer<T>> handler) {
		return list.addListItemMouseOverHandler(handler);
	}

	@Override
	public HandlerRegistration addListItemMouseOutHandler(ListItemMouseOutHandler<ItemRenderer<T>> handler) {
		return list.addListItemMouseOutHandler(handler);
	}

	@Override
	public boolean contains(ItemRenderer<T> listItem) {
		return list.contains(listItem);
	}

	@Override
	public ItemRenderer<T> getItem(int index) {
		return list.getItem(index);
	}

	@Override
	public int getItemCount() {
		return list.getItemCount();
	}

	@Override
	public int getItemIndex(ItemRenderer<T> listItem) {
		return list.getItemIndex(listItem);
	}

	@Override
	public void insert(ItemRenderer<T> listItem, int index) {
		list.insert(listItem, index);
	}

	@Override
	public boolean isEmpty() {
		return list.isEmpty();
	}

	@Override
	public boolean remove(int listIndex) {
		return list.remove(listIndex);
	}

	@Override
	public void removeAll(Collection<ItemRenderer<T>> listItems) {
		list.removeAll(listItems);
	}

	@Override
	public List<ItemRenderer<T>> subList(int fromIndex, int toIndex) {
		return list.subList(fromIndex, toIndex);
	}

	@Override
	public boolean addListItemStyleDependentName(int index, String styleSuffix) {
		return list.addListItemStyleDependentName(index, styleSuffix);
	}

	@Override
	public boolean addListItemStyleDependentName(ItemRenderer<T> listItem, String styleSuffix) {
		return list.addListItemStyleDependentName(listItem, styleSuffix);
	}

	@Override
	public boolean removeListItemStyleDependentName(int index, String styleSuffix) {
		return list.removeListItemStyleDependentName(index, styleSuffix);
	}

	@Override
	public boolean removeListItemStyleDependentName(ItemRenderer<T> listItem, String styleSuffix) {
		return list.removeListItemStyleDependentName(listItem, styleSuffix);
	}

}
